/*
 *  Licensed Materials - Property of IBM
 *  5725-G92 (C) Copyright IBM Corp. 2011, 2013. All Rights Reserved.
 *  US Government Users Restricted Rights - Use, duplication or
 *  disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
 */

/**
 *  WL.Server.invokeHttp(parameters) accepts the following json object as an argument:
 *  
 *  {
 *  	// Mandatory 
 *  	method : 'get' , 'post', 'delete' , 'put' or 'head' 
 *  	path: value,
 *  	
 *  	// Optional 
 *  	returnedContentType: any known mime-type or one of "json", "css", "csv", "javascript", "plain", "xml", "html"  
 *  	returnedContentEncoding : 'encoding', 
 *  	parameters: {name1: value1, ... }, 
 *  	headers: {name1: value1, ... }, 
 *  	cookies: {name1: value1, ... }, 
 *  	body: { 
 *  		contentType: 'text/xml; charset=utf-8' or similar value, 
 *  		content: stringValue 
 *  	}, 
 *  	transformation: { 
 *  		type: 'default', or 'xslFile', 
 *  		xslFile: fileName 
 *  	} 
 *  } 
 */

function getEmployee(id) { 
	var token = '655d097e4bd28fd6adfd2f8bddd61008239d4ea9';
//	var token = getToken() ;
	var input = {
			method: 'get',
			returnedContentType: 'json',
			path: '/symfony/web/api/' + token + '/employee/' + id + "/show" 
	}; 
	return WL.Server.invokeHttp(input);
}


function getEmployeeList() {
//	var token = getToken() ;
	var token = '655d097e4bd28fd6adfd2f8bddd61008239d4ea9';
	
	var input = {
			method: 'get', 
			returnedContentType: 'json' , 
			path: '/symfony/web/api/' + token + '/employee/list' 
	};
	return WL.Server.invokeHttp(input);

}


function updateAttachment (id, json_data) {
//	var token = getToken() ;
	var token = '655d097e4bd28fd6adfd2f8bddd61008239d4ea9';
	var input = {
			method: 'post' , 
			returnedContentType:'json',
			path: '/symfony/web/api/' + token + '/employee/' + id + '/updateAttachment' , 
			data: json_data
	};
	
	return WL.Server.invokeHttp(input);
}

function getLeaveByEmployee(id ) {
//	var token = getToken() ;
	var token = '655d097e4bd28fd6adfd2f8bddd61008239d4ea9';
	var input = {
			method: 'get' , 
			returnedContentType:'json',
			path: '/symfony/web/api/' + token + '/leave/' + id + '/updateLeaveStatus' 
	};
	
	return WL.Server.invokeHttp(input);
}


function createLeave() {
	var token = '655d097e4bd28fd6adfd2f8bddd61008239d4ea9';
	var input = {
			method: 'post' , 
			returnedContentType:'json',
			path: '/symfony/web/api/' + token + '/leave/create' , 
			data: json_data
	};
	
	return WL.Server.invokeHttp(input);
}

function updateLeaveStatus (id) {
	
}


function updateContactDetail(id, json_data) {
//	var token = getToken() ;
	var token = '655d097e4bd28fd6adfd2f8bddd61008239d4ea9';
	var input = {
			method: 'post' , 
			returnedContentType:'json',
			path: '/symfony/web/api/' + token + '/employee/' + id + '/updateContactDetail' , 
			data: json_data
	};
	return WL.Server.invokeHttp(input);
}

/**
 * 
 * @param interest
 *            must be one of the following: world, africa, sport, technology, ...
 *            (The list can be found in http://edition.cnn.com/services/rss/)
 * @returns json list of items
 */
function getToken(){
	var activeUser = JSON.parse(JSON.stringify(WL.Server.getActiveUser("CustomAuthenticatorRealm")));

	var token = activeUser.attributes.authenticationKey;
	//var token=activeUser.credentials;
//	var s = activeUser.credentials;
	//var s = "123";
	return token;
}